<?php

/**
 * @Author: liuhongbin
 * @Email: 514660094@qq.com
 * @Date: 2019-02-12 16:15:10
 * @Description:
 * @LastEditors: liuhongbin
 * @LastEditTime: xxx
 */

namespace app\adminapi\controller\v1\platform\douyin;


use app\adminapi\controller\v1\platform\PlatformController;
use app\common\model\platform\PlatformSetting;
use EasyWeChat\MiniProgram\Mall\ForwardsMall;
use FormBuilder\Driver\CustomComponent;
use FormBuilder\Driver\FormComponent;
use hiduoke\services\douyin\DouyinScopes;
use hiduoke\services\FormBuilder as Form;
use hiduoke\services\formBuilder\DkDyScopesSelect;
use think\App;

class DouyinSetting extends PlatformController
{
    /**
     * @var PlatformSetting
     */
    private $model;

    public function __construct(App $app)
    {
        parent::__construct($app);
        $this->model = new PlatformSetting();
    }

    public function getDouyinScopes()
    {
        $scope = new DouyinScopes();
        return $this->success('', $scope->all_scopes);
    }

    public function Scopes()
    {

        $plaid = $this->request->param('plaid', 0);
        if ($this->request->isPost()) {
            $formData = $this->request->param('formData', []);
            $res = $this->model->setValueByKey($formData, "Scopes", $plaid);
            return $this->success("修改成功", $res);
        } else {
            $rule = array();
            //创建表单
            $res = $this->model->getValueByKey("Scopes", $plaid);
            $form = Form::createForm("/adminapi/platform/douyin/setting/Scopes?plaid=" . $plaid)->setMethod("post");
            //新增表单
            $rule[] = (new DkDyScopesSelect("scopes", "选择权限", $res['scopes'] ?? []))->info("设置应用授权登录的时候需要的权限，如果未开通，授权将会失败");
            $rule[] = Form::dkInput('extra_scopes', '额外权限', $res['extra_scopes'] ?? '', "当没找到页面上的权限后，可以手动填写权限，每个权限用英文逗号隔开");
            $form->setTitle("")->setRule($rule);
            return $this->success("", Form::getFormData($form));
        }
    }

}
